package com.ymatou.iapi.godfreightmgr.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.ymatou.iapi.godfreightmgr.parameter.CreateCollectionGoodsAddressBean;
import com.ymatou.iapi.godfreightmgr.parameter.SetCollectionGoodsBySellerBean;
import com.ymatou.iapi.godfreightmgr.service.SetCollectionGoodsBySellerCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godfreight.DeliveryPatternConfig;
/**
*商户修改自提开关
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetCollectionGoodsBySeller{
	private static SetCollectionGoodsBySellerBean setcollectiongoodsbysellerBean;
	private static SetCollectionGoodsBySellerCall setcollectiongoodsbysellerCall;
	com.ymttest.database.sqlwapper.godfreight.CollectionGoodsWapper CollectionGoodsWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商户修改自提开关");
	}

	@Before
	public void caseUp() {
		setcollectiongoodsbysellerBean=new SetCollectionGoodsBySellerBean();
		setcollectiongoodsbysellerCall=new SetCollectionGoodsBySellerCall();
		CollectionGoodsWapper=new com.ymttest.database.sqlwapper.godfreight.CollectionGoodsWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setcollectiongoodsbysellerCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetCollectionGoodsBySeller_001() {
		Logger.start(true,"商户修改自提开关成功-第一次打开");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			setcollectiongoodsbysellerBean.setEnableCollectionGoods(true);
			setcollectiongoodsbysellerBean.setSellerId(mchId_channl);
			setcollectiongoodsbysellerCall.setData(setcollectiongoodsbysellerBean);
			setcollectiongoodsbysellerCall.callService();			
			Logger.verifyEquals("200", setcollectiongoodsbysellerCall.getString("code"), "验证code");
			DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(mchId_channl).get(0);
			Logger.verifyEquals(true, dp.getEnableCollectionGoods(), "验证运营开启");
			Logger.verifyEquals(true, dp.getCollectionGoods(), "验证商家开启自提");
			Logger.verifyEquals(true, dp.getExpressDelivery(), "验证商家开启快递");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsBySeller_002() {
		Logger.start(true,"不输入sellerId失败");
		try {
			setcollectiongoodsbysellerBean.setEnableCollectionGoods(false);
			setcollectiongoodsbysellerCall.setData(setcollectiongoodsbysellerBean);
			setcollectiongoodsbysellerCall.callService();			
			Logger.verifyEquals("400", setcollectiongoodsbysellerCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsBySeller_003() {
		Logger.start(true,"不输入enableCollectionGoods失败");
		try {
			setcollectiongoodsbysellerBean.setSellerId(1);
			setcollectiongoodsbysellerCall.setData(setcollectiongoodsbysellerBean);
			setcollectiongoodsbysellerCall.callService();			
			Logger.verifyEquals("400", setcollectiongoodsbysellerCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsBySeller_004() {
		Logger.start(true,"商户修改自提开关成功-关闭");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
			setcollectiongoodsbysellerBean.setEnableCollectionGoods(false);
			setcollectiongoodsbysellerBean.setSellerId(mchId_channl);
			setcollectiongoodsbysellerCall.setData(setcollectiongoodsbysellerBean);
			setcollectiongoodsbysellerCall.callService();			
			Logger.verifyEquals("200", setcollectiongoodsbysellerCall.getString("code"), "验证code");
			DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(mchId_channl).get(0);
			Logger.verifyEquals(true, dp.getEnableCollectionGoods(), "验证运营开启");
			Logger.verifyEquals(false, dp.getCollectionGoods(), "验证商家开启自提");
			Logger.verifyEquals(true, dp.getExpressDelivery(), "验证商家开启快递");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsBySeller_005() {
		Logger.start(true,"该店铺中有仅上门自提商品,不可关闭该功能");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId_channl, "",
                    true);
			addAgentProductBean.setExpressDelivery(false);
			addAgentProductBean.setCollectionGoods(true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			setcollectiongoodsbysellerBean.setEnableCollectionGoods(false);
			setcollectiongoodsbysellerBean.setSellerId(mchId_channl);
			setcollectiongoodsbysellerCall.setData(setcollectiongoodsbysellerBean);
			setcollectiongoodsbysellerCall.callService();			
			Logger.verifyEquals("400", setcollectiongoodsbysellerCall.getString("code"), "失败");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsBySeller_006() {
		Logger.start(true,"商户修改自提开关成功-反复开关");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
			setcollectiongoodsbysellerBean.setEnableCollectionGoods(false);
			setcollectiongoodsbysellerBean.setSellerId(mchId_channl);
			setcollectiongoodsbysellerCall.setData(setcollectiongoodsbysellerBean);
			setcollectiongoodsbysellerCall.callService();			
			Logger.verifyEquals("200", setcollectiongoodsbysellerCall.getString("code"), "验证code");
			DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(mchId_channl).get(0);
			Logger.verifyEquals(true, dp.getEnableCollectionGoods(), "验证运营开启");
			Logger.verifyEquals(false, dp.getCollectionGoods(), "验证商家开启自提");
			Logger.verifyEquals(true, dp.getExpressDelivery(), "验证商家开启快递");
			
			
			setcollectiongoodsbysellerBean.setEnableCollectionGoods(true);
			setcollectiongoodsbysellerBean.setSellerId(mchId_channl);
			setcollectiongoodsbysellerCall.setData(setcollectiongoodsbysellerBean);
			setcollectiongoodsbysellerCall.callService();			
			Logger.verifyEquals("200", setcollectiongoodsbysellerCall.getString("code"), "验证code");
			dp = CollectionGoodsWapper.selectDeliveryPatternConfig(mchId_channl).get(0);
			Logger.verifyEquals(true, dp.getEnableCollectionGoods(), "验证运营开启");
			Logger.verifyEquals(true, dp.getCollectionGoods(), "验证商家开启自提");
			Logger.verifyEquals(true, dp.getExpressDelivery(), "验证商家开启快递");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsBySeller_007() {
		Logger.start(true,"快递开关关闭时不可关闭自提开关");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
			GodfreightmgrService.setExpressDeliveryBySellerCall(mchId_channl, false);
			setcollectiongoodsbysellerBean.setEnableCollectionGoods(false);
			setcollectiongoodsbysellerBean.setSellerId(mchId_channl);
			setcollectiongoodsbysellerCall.setData(setcollectiongoodsbysellerBean);
			setcollectiongoodsbysellerCall.callService();			
			Logger.verifyEquals("400", setcollectiongoodsbysellerCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsBySeller_008() {
		Logger.start(true,"运营开关关闭时不可开启自提开关");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, false);
			setcollectiongoodsbysellerBean.setEnableCollectionGoods(true);
			setcollectiongoodsbysellerBean.setSellerId(mchId_channl);
			setcollectiongoodsbysellerCall.setData(setcollectiongoodsbysellerBean);
			setcollectiongoodsbysellerCall.callService();			
			Logger.verifyEquals("400", setcollectiongoodsbysellerCall.getString("code"), "验证code");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsBySeller_009() {
		Logger.start(true,"该店铺中有仅快递发货商品,关闭成功");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//开启运营
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId_channl, "",
                    true);
			addAgentProductBean.setExpressDelivery(true);
			addAgentProductBean.setCollectionGoods(false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			
			
			setcollectiongoodsbysellerBean.setEnableCollectionGoods(false);
			setcollectiongoodsbysellerBean.setSellerId(mchId_channl);
			setcollectiongoodsbysellerCall.setData(setcollectiongoodsbysellerBean);
			setcollectiongoodsbysellerCall.callService();			
			Logger.verifyEquals("200", setcollectiongoodsbysellerCall.getString("code"), "验证code");
			DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(mchId_channl).get(0);
			Logger.verifyEquals(true, dp.getEnableCollectionGoods(), "验证运营开启");
			Logger.verifyEquals(false, dp.getCollectionGoods(), "验证商家开启自提");
			Logger.verifyEquals(true, dp.getExpressDelivery(), "验证商家开启快递");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetCollectionGoodsBySeller_010() {
		Logger.start(true,"该店铺中有上门提货-快递发货都支持商品,关闭成功");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//开启运营
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId_channl, "",
                    true);
			addAgentProductBean.setExpressDelivery(true);
			addAgentProductBean.setCollectionGoods(true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			
			
			setcollectiongoodsbysellerBean.setEnableCollectionGoods(false);
			setcollectiongoodsbysellerBean.setSellerId(mchId_channl);
			setcollectiongoodsbysellerCall.setData(setcollectiongoodsbysellerBean);
			setcollectiongoodsbysellerCall.callService();			
			Logger.verifyEquals("200", setcollectiongoodsbysellerCall.getString("code"), "验证code");
			DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(mchId_channl).get(0);
			Logger.verifyEquals(true, dp.getEnableCollectionGoods(), "验证运营开启");
			Logger.verifyEquals(false, dp.getCollectionGoods(), "验证商家开启自提");
			Logger.verifyEquals(true, dp.getExpressDelivery(), "验证商家开启快递");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}